package com.prb.common.statistical;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

public class TimeMetrics {


    // 接口 + 耗时时间
    public static Map<String , Metrics> metricsMap = new ConcurrentHashMap<>();

    public static TimeMetrics instance = new TimeMetrics();


    public void addMetrics(String serverName , String ip , Integer port) {

        metricsMap.put(serverName , new Metrics(ip , port , System.currentTimeMillis() , 0l));
    }


    public void calculateTime(String serverName){

        Metrics metrics = metricsMap.get(serverName);
        metrics.setEnd(System.currentTimeMillis() - metrics.getStart());
    }


    @Data
    @NoArgsConstructor
    @AllArgsConstructor
    public class Metrics {

        private String ip;

        private Integer port;

        private Long start;

        private Long end;



    }

}
